#use as irb -r lib/console.rb -I ./lib/ from parent dir
require "Logger"
require "Tokenizer"
require "Parser"
require "ParserUtils"

def parse(file)
  log = Logger.new(STDOUT)
  log.datetime_format = "%Y-%m-%d %H:%M:%S "
  log.level = Logger::Severity::INFO

  tok = Tokenizer.new(file, log)
  
  pars = Parser.new(tok,log)
  begin
    result = pars.parse()
  rescue CompilerException => e
    puts "Error happened: #{e} at <#{e.line},#{e.pos}>"
  else
    return result
  end
end

def parse_test(n)
  parse("./test/Parser/#{n}.in")
end